﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Text;
using Vmago.Models.DBML;
using System.IO;

namespace System.Web.Mvc
{
    /// <summary>
    /// 图片扩展类
    /// </summary>
    public static class HtmlHelperExtensions
    {
        public static string Image(this HtmlHelper helper, String src)
        {
            return String.Format(@"<img src=""{0}"" alt=""{0}""/>", src);
        }

        public static string Image(this HtmlHelper helper, Object src, Object alt, Int32 width, Int32 height)
        {
            //创意某一个Tag的TagBuilder
            var builder = new TagBuilder("img");

            builder.MergeAttribute("src", String.Format("../../Content/img/TrademarkLogo/{0}", src));
            builder.MergeAttribute("alt", String.Format("{0}", alt));
            builder.MergeAttribute("width", width.ToString());
            builder.MergeAttribute("height", height.ToString());

            return builder.ToString(TagRenderMode.Normal);
        }

        public static string CheckBox(this HtmlHelper htmlHelper, string name, string value)
        {
            //创意某一个Tag的TagBuilder
            var builder = new TagBuilder("input");

            builder.MergeAttribute("type", "checkbox");
            builder.MergeAttribute("name", name);
            builder.MergeAttribute("value", value);

            return builder.ToString(TagRenderMode.Normal);

        }

        public static string TextBox(this HtmlHelper htmlHelper, string name, string value, String type)
        {
            var builder = new TagBuilder("input");

            builder.MergeAttribute("type", type);
            builder.MergeAttribute("name", name);
            builder.MergeAttribute("value", value);

            return builder.ToString(TagRenderMode.Normal);

        }

        #region 专用控件：Views/Index/Index_RightMap.ascx

        /// <summary>
        /// 专用控件：Views/Index/Index_RightMap.ascx
        /// </summary>
        /// <param name="htmlHelper"></param>
        /// <param name="oShop"></param>
        /// <returns></returns>
        public static string _V_I_I_RM_GetMarker(this HtmlHelper htmlHelper, vw_recShop oShop)
        {
            String strImgPath = System.AppDomain.CurrentDomain.BaseDirectory + oShop.imageLocation.Substring(1, oShop.imageLocation.Length - 1);
            
            if (!File.Exists(strImgPath)) { strImgPath = "../../Content/img/home/iniImg.bmp"; }
            else { strImgPath = String.Format("../..{0}", oShop.imageLocation); }

            String strHtml = "<table align=left>" +
                                    "<tr>" +
                                        "<td align=left width=260px>" + oShop.name +
                                        "<img src=" + strImgPath + " height=80 width=100 hspace=5 align=left></img>" +
                                        "<br/>1" + oShop.description.Replace("\r\n", "") +
                                        "</td>" +
                                    "</tr>" +
                                    "<tr valign=top>" +
                                        "<td valign=top align=left></td>" +
                                    "</tr>" +
                                    "<tr>" +
                                        "<td>" +
                                            "<a href = /City/Trademark/" + oShop.shopID + ">更多详细信息</a>" +
                                        "</td>" +
                                    "</tr>" +
                                "</table>";

            return strHtml;
        }

        #endregion        
    }
}
